package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DeviceStatistics;
import com.ruoyi.system.service.IDeviceStatisticsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备上线数量Controller
 * //20250214 云计算-智能车联-04-数据统计
 * @author 刘进祥
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/system/statistics")
public class DeviceStatisticsController extends BaseController
{
    @Autowired
    private IDeviceStatisticsService deviceStatisticsService;

    /**
     * 查询设备上线数量列表
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceStatistics deviceStatistics)
    {
        startPage();
        List<DeviceStatistics> list = deviceStatisticsService.selectDeviceStatisticsList(deviceStatistics);
        return getDataTable(list);
    }

    /**
     * 导出设备上线数量列表
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:export')")
    @Log(title = "设备上线数量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceStatistics deviceStatistics)
    {
        List<DeviceStatistics> list = deviceStatisticsService.selectDeviceStatisticsList(deviceStatistics);
        ExcelUtil<DeviceStatistics> util = new ExcelUtil<DeviceStatistics>(DeviceStatistics.class);
        util.exportExcel(response, list, "设备上线数量数据");
    }

    /**
     * 获取设备上线数量详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceStatisticsService.selectDeviceStatisticsById(id));
    }

    /**
     * 新增设备上线数量
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:add')")
    @Log(title = "设备上线数量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceStatistics deviceStatistics)
    {
        return toAjax(deviceStatisticsService.insertDeviceStatistics(deviceStatistics));
    }

    /**
     * 修改设备上线数量
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:edit')")
    @Log(title = "设备上线数量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceStatistics deviceStatistics)
    {
        return toAjax(deviceStatisticsService.updateDeviceStatistics(deviceStatistics));
    }

    /**
     * 删除设备上线数量
     */
    @PreAuthorize("@ss.hasPermi('system:statistics:remove')")
    @Log(title = "设备上线数量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceStatisticsService.deleteDeviceStatisticsByIds(ids));
    }
}
